package economy;

public class Item {
	private String name;
	private int id;
	private int baseValue;
	private int supplyFactor;
	private int profitFactor;
	private int currentSupply;
	private int buyPrice;
	private int sellPrice;

	public Item(String name, int id, int baseValue, int supplyFactor,
			int profitFactor, int currentSupply) {
		this.name = name;
		this.id = id;
		this.baseValue = baseValue;
		this.supplyFactor = supplyFactor;
		this.profitFactor = profitFactor;
		this.currentSupply = currentSupply;
		this.updatePrices();
	}

	public int add(int quantity) {
		currentSupply = currentSupply + quantity;
		this.updatePrices();
		return currentSupply;
	}

	public int buyPrice() {
		return buyPrice;
	}

	public int currentSupply() {
		return currentSupply;
	}

	public int id() {
		return id;
	}

	public String name() {
		return name;
	}

	public int sellPrice() {
		return sellPrice;
	}

	public int setCurrentSupply(int quantity) {
		currentSupply = quantity;
		return currentSupply;
	}

	public int subtract(int quantity) {
		currentSupply = currentSupply - quantity;
		this.updatePrices();
		return currentSupply;
	}

	public void updatePrices() {
		buyPrice = (int) (baseValue
				* (1 - (0.5 * currentSupply / supplyFactor)) * (1 - profitFactor));
		sellPrice = (int) (baseValue
				* (1 - (0.5 * currentSupply / supplyFactor)) * (1 + profitFactor));
	}
}
